﻿using Common;
using Framework;
using Module.M2;
using UnityEngine.UI;

public class M2View : View
{
    private InputField input;
    private ChildView childView;
    private StaticView staticVeiw;

    private void Awake()
    {
        transform.GetButton("ModuleEventBtn").onClick.AddListener(OnModuleEvent);
        transform.GetButton("EventBtn").onClick.AddListener(OnEventBtn);

        input = transform.GetInputField("InputField");
        
        transform.GetButton("CloseBtn").onClick.AddListener(OnClose);
        transform.GetButton("ChildViewBtn").onClick.AddListener(OnChildView);
    }

    protected override void Init()
    {
        staticVeiw = ConnectView<StaticView>(transform.Find("StaticView"));
    }

    protected override void RegisterEvent()
    {
        
    }

    private void OnChildView()
    {
        childView = AddChildView<ChildView>(modulePath + "View/ChildView.prefab");
        
    }

    private void OnClose()
    {
        ModuleManager.RemoveModule(ModuleName.M2);
    }

    public void SetText(string text)
    {
        input.text = text;
    }
    
    private void OnEventBtn()
    {
        TriggerEvent(M2Event.M2);
    }

    private void OnModuleEvent()
    {
        TriggerModuleEvent(GlobalEvent.ModuleEvent, "来自M2模块的Event");
    }
}